package com.tidc.consumer8001.controller.check;

import com.tidc.commonality.api.StudentCheckApi;
import com.tidc.commonality.ov.UserOV;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.javassist.NotFoundException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * @ClassNmae StudentCheckController
 * @Description TODO
 * @Author 冯涛滔
 **/
@RestController
@CrossOrigin
@RequestMapping("/student")
public class StudentCheckController {
	@Autowired
	private StudentCheckApi checkApi;
	@ApiOperation("使用teamID和队长id获取整个队伍的队员的名字列表")
	@GetMapping("/check/team/{student_id}/{team_id}")
	public UserOV teamId(@PathVariable("student_id")int student_id, @PathVariable("team_id") int team_id) throws NotFoundException {
		System.out.println(student_id);
		return checkApi.teamId(student_id,team_id);
	}

	@ApiOperation("根据比赛id来返回比赛的详细信息 具体是/check/match/id(这里是数字,动态的)")
	@RequestMapping(value = "/check/match/{id}",method = RequestMethod.GET)
	public UserOV getmatches(@PathVariable("id") int id){
		return checkApi.getmatches(id);
	}

	@ApiOperation("当前登录的学生查看自己创建的所有比赛 但是如果没用创建过比赛就会返回一个空数组")
	@RequestMapping(value="/check/works",method = RequestMethod.GET)
	public UserOV myWorks(String token){
		return checkApi.myWorks(token);
	}

	@ApiOperation("根据参赛作品的id来查看该作品的详细信息包括队伍人员查询 具体是/check/work/id(这里是数字,动态的),如果是老师着可以无条件查询学生只能查看自己的")
	@RequestMapping(value = "/check/work/{id}",method = RequestMethod.GET)
	public UserOV getWorks(@PathVariable("id") int id,String token){
		return checkApi.getWorks(id,token);
	}

	@ApiOperation(value = "根据比赛id查看分数排行榜 返回所有人的比赛名字属性和分数总分和平均分")
	@RequestMapping(value = "/check/score/top/{id}",method=RequestMethod.GET)
	public UserOV getScoreTop(@PathVariable int id){
		return checkApi.getScoreTop(id);
	}

	@ApiOperation(value = "查询所有的比赛")
	@RequestMapping(value = "/check/match",method = RequestMethod.GET)
	public UserOV getMatches(){
		return checkApi.getMatches();
	}

	@ApiOperation(value = "查询当前学生的学校的比赛")
	@RequestMapping(value = "/check/school/match",method = RequestMethod.GET)
	public UserOV getMyMatches(String token){
		return checkApi.getMyMatches(token);
	}

	@ApiOperation(value = "首页的比赛排行榜一共有8条")
	@RequestMapping(value = "/check/index/rank",method = RequestMethod.GET)
	public UserOV getIndexRank(){
		return checkApi.getIndexRank();
	}

	@ApiOperation(value = "根据比赛类别查询当前类别的所有比赛")
	@RequestMapping(value = "/check/match/domain",method = RequestMethod.GET)
	public UserOV getDomainMatch(@RequestParam(defaultValue = "计算机") String domain, HttpServletRequest req){
		return getDomainMatch(domain,req);
	}

	@ApiOperation(value = "模糊查找比赛")
	@RequestMapping(value = "/check/like/match",method = RequestMethod.GET)
	public UserOV likeMatch(@RequestParam String name){
		return checkApi.likeMatch(name);
	}

	@ApiOperation("根据email查询学生")
	@RequestMapping(value = "/check/student",method = RequestMethod.GET)
	public UserOV checkStudent( String email){
		return checkApi.checkStudent(email);
	}

	@ApiOperation("使用teamID获取整个team")
	@RequestMapping(value = "/check/team/{id}",method = RequestMethod.GET)
	public UserOV getTeam(@PathVariable("id")int id,String token){
		return checkApi.getTeam(id,token);
	}

	@ApiOperation("按分类获取所有以开始评分的已开始评分的比赛列表")
	@RequestMapping(value = "/check/top/match",method = RequestMethod.GET)
	public UserOV checkStudentMatch(String domain){
		return checkStudentMatch(domain);
	}
}
